/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fix.it.source.fixit;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Biserka
 */
@Entity
@Table(name = "PROBLEM")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Problem.findAll", query = "SELECT p FROM Problem p"),
    @NamedQuery(name = "Problem.findLatest", query = "SELECT p.id FROM Problem p ORDER BY p.id DESC"),
    @NamedQuery(name = "Problem.findById", query = "SELECT p FROM Problem p WHERE p.id = :id"),
    @NamedQuery(name = "Problem.findByProblemname", query = "SELECT p FROM Problem p WHERE p.problemname = :problemname"),
    @NamedQuery(name = "Problem.findByIssolved", query = "SELECT p FROM Problem p WHERE p.issolved = :issolved"),
    @NamedQuery(name = "Problem.findByImportance", query = "SELECT p FROM Problem p WHERE p.importance = :importance"),
    @NamedQuery(name = "Problem.findByReportdate", query = "SELECT p FROM Problem p WHERE p.reportdate = :reportdate")})
public class Problem implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Basic(optional = false)
    @NotNull
    @Column(name = "ID")
    private Long id;
    @Size(max = 25)
    @Column(name = "PROBLEMNAME")
    private String problemname;
    @Basic(optional = false)
    @NotNull
    @Column(name = "ISSOLVED")
    private int issolved;
    @Basic(optional = false)
    @NotNull
    @Column(name = "IMPORTANCE")
    private int importance;
    @Basic(optional = false)
    @NotNull
    @Column(name = "REPORTDATE")
    @Temporal(TemporalType.DATE)
    private Date reportdate;
    @JoinColumn(name = "STREETID", referencedColumnName = "ID")
    @ManyToOne(optional = false)
    private Street streetid;
    @JoinColumn(name = "PROBLEMTYPEID", referencedColumnName = "ID")
    @ManyToOne(optional = false)
    private Problemtype problemtypeid;
    @JoinColumn(name = "MUNICIPALITYID", referencedColumnName = "ID")
    @ManyToOne(optional = false)
    private Municipality municipalityid;
    @JoinColumn(name = "USERID", referencedColumnName = "ID")
    @ManyToOne(optional = false)
    private Localuser userid;
    @JoinColumn(name = "AUTHORITYID", referencedColumnName = "ID")
    @ManyToOne(optional = false)
    private Authority authorityid;

    public Problem() {
    }

    public Problem(Long id) {
        this.id = id;
    }

    public Problem(Long id, int issolved, int importance, Date reportdate) {
        this.id = id;
        this.issolved = issolved;
        this.importance = importance;
        this.reportdate = reportdate;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getProblemname() {
        return problemname;
    }

    public void setProblemname(String problemname) {
        this.problemname = problemname;
    }

    public int getIssolved() {
        return issolved;
    }

    public void setIssolved(int issolved) {
        this.issolved = issolved;
    }

    public int getImportance() {
        return importance;
    }

    public void setImportance(int importance) {
        this.importance = importance;
    }

    public Date getReportdate() {
        return reportdate;
    }
    public String getReportdateString() {
        SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd-MM-yyyy");
        String date = DATE_FORMAT.format(reportdate);
        return date;
    }

    public void setReportdate(Date reportdate) {
        this.reportdate = reportdate;
    }

    public Street getStreetid() {
        return streetid;
    }

    public void setStreetid(Street streetid) {
        this.streetid = streetid;
    }

    public Problemtype getProblemtypeid() {
        return problemtypeid;
    }

    public void setProblemtypeid(Problemtype problemtypeid) {
        this.problemtypeid = problemtypeid;
    }

    public Municipality getMunicipalityid() {
        return municipalityid;
    }

    public void setMunicipalityid(Municipality municipalityid) {
        this.municipalityid = municipalityid;
    }

    public Localuser getUserid() {
        return userid;
    }

    public void setUserid(Localuser userid) {
        this.userid = userid;
    }

    public Authority getAuthorityid() {
        return authorityid;
    }

    public void setAuthorityid(Authority authorityid) {
        this.authorityid = authorityid;
    }
    
    


    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Problem)) {
            return false;
        }
        Problem other = (Problem) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "fix.it.source.fixit.Problem[ id=" + id + " ]";
    }
    
}
